package com.leigang.resource.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class LogAspect {

    public LogAspect(){
        log.info("LogAspect  已经加载");
    }

    @Pointcut("execution(public * com.leigang.resource.controller..*.*(..))")
    public void pointcut() {
    }

    @Before(value = "pointcut()", argNames = "joinPoint")
    public void before(JoinPoint joinPoint) {
        log.info("LogAspect before ...");
        String methodName = joinPoint.getSignature().toShortString();
        String key = "submit:" + methodName;
    }

    @Around(value = "pointcut()", argNames = "joinPoint")
    public Object around(ProceedingJoinPoint joinPoint){
        log.info("LogAspect around ...");
        // 获取方法参数和注解值
        Object[] args = joinPoint.getArgs();
        String methodName = joinPoint.getSignature().toShortString();
        return args;
    }
}
